{layout name="layouts/main_slight" /}
<style>
    body{padding: 10px;}
</style>
<?php

use app\admin\model\field\system\UserToken;

$get = $get ?? [];
$easyForm = new \app\admin\extend\common\html2\EasyForm($get, UserToken::class);
?>
<body>

<!-- 内容主体区域 -->
<div style="padding: 15px;">
    <?php

    $url = empty($get['id']) ? './add' : './update';
    ?>
    <form class="layui-form layui-form-pane1" method="post" action="<?php echo $url; ?>" lay-filter="first">
        <?php
        echo $easyForm->hidden('id');
        echo $easyForm->setRequire()->addVerify('required')->text('username');
        echo $easyForm->setRequire()->addVerify('required')->text('token');
        echo $easyForm->setRequire()->addVerify('required')->text('expiretime');
        
        ?>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" type="button" lay-submit lay-filter="*">提交</button>
                <button onclick="closeIframe();" type="button" class="layui-btn">取消</button>
            </div>
        </div>
    </form>

    <br><br><br>

    <script>

        layui.use(['form'], function(){
            const $ = layui.$
            const form = layui.form

            //自定义验证规则
            form.verify({

            })

            //监听提交
            form.on('submit(*)', function(data){
                $.post('<?php echo $url ?>' , data.field , function(d) {
                    if(d.code != 0) {
                        //返回失败
                        layer.msg(d.msg)
                        return false
                    }
                    layer.msg('成功')
                    setTimeout(function() {
                        const index = parent.layer.getFrameIndex(window.name) //先得到当前iframe层的索引
                        parent.layer.close(index) //再执行关闭
                        parent.layui.table.reload('list')
                    },1000)
                })
                return false
            })

        })

    </script>
</div>

</body>
